<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<div class="modal-dialog x-modal-dialog" style="width: 600px;">

  <div class="modal-content">

    <div class="modal-header x-breadcrumb clearfix">

      <h2><i class="glyphicon glyphicon-fire" title=""></i>&nbsp;&nbsp;<span>重排体验课</span></h2>

      <button type="button" class="close" data-dismiss="modal">&times;</button>

    </div>

    <c:set var="readyUrl" value="${ctx.host}/individual-rounds/${courseSchedule.courseRound.id}/schedules/${courseSchedule.id}"></c:set>
    <c:set var="expiryUrl" value="${ctx.host}/expiry-schedules/${courseSchedule.id}/time"></c:set>
    <form class="form-horizontal" method="POST" action="${courseSchedule.scheduleStatus.ready ? readyUrl : expiryUrl}" data-validate = "true">

      <input type="hidden" name="_method" value="PATCH">
      <c:if test="${currentPrincipal.siteManager or currentPrincipal.siteServer}">
        <input type="hidden" name="siteId" value="${currentPrincipal.site.id}">
      </c:if>
      <input type="hidden" name="expUserMobile" value="${user.mobile}">
      <input type="hidden" name="expUserName" value="${user.name}">

      <div class="modal-body">
        <c:if test="${empty currentPrincipal.site}">
          <div class="form-group x-form-group">
            <label class="col-xs-3 control-label">门店</label>
            <div class="col-xs-7" style="width: 60%;">
              <select name="siteId" class="form-control select2" data-validate="required">
                <c:forEach var="site" items="${persist.getSites(currentPrincipal.id)}">
                  <c:if test="${!site.disabled}">
                    <option value ="${site.id}" ${courseSchedule.site.id eq site.id ? 'selected' :''}>${site.name}</option>
                  </c:if>
                </c:forEach>
              </select>
            </div>
          </div>
        </c:if>
        
        <div class="form-group x-form-group">
          <label class="col-xs-3 control-label">教练</label>
          <div class="col-xs-7" style="width: 60%;">
            <select name="coachId" class="form-control select2" data-validate="required">
              <option></option>
              <c:forEach var="coach" items="${persist.coaches(currentPrincipal.id, currentPrincipal.site.id)}">
                 <option value = "${coach.key}" ${courseSchedule.coach.id eq coach.key ? 'selected' :''}>${coach.value.name}</option>
              </c:forEach>
            </select>
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="col-xs-3 control-label">日期</label>
          <div class="col-xs-7" style="width: 60%;">
            <input type="text" class="form-control date" name="${courseSchedule.scheduleStatus.ready ? 'day' : 'occurDate'}" value="<fmt:formatDate type='date' value='${courseSchedule.occurDate}'/>" data-validate="required" placeholder="请输入日期"/>
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="col-xs-3 control-label">时间</label>
          <div class="col-xs-7 hour-item"  style="width: 60%;">
            <select name="${courseSchedule.scheduleStatus.ready ? 'hour' : 'occurHour'}" class="form-control select2" data-validate="required">
              <option></option>
              <c:forEach var="freeTime" items="${persist.scheduleTime()}">
                <option value = "${freeTime}" ${courseSchedule.occurHour eq freeTime ? 'selected' : ''}>${freeTime} ~ ${persist.getExpEndTime(freeTime)}</option>
              </c:forEach>
            </select>
          </div>
        </div>

        <div class="form-group x-form-group">
          <label class="col-xs-3 control-label">区域类型</label>
          <div class="col-xs-7" style="width: 60%;">
            <select name="roomType" class="form-control select2" data-validate="required">
              <option></option>
              <c:forEach var="roomType" items="${enums['roomType']}">
                 <option value = "${roomType}" ${courseSchedule.roomType.alias eq roomType.alias ? 'selected' : ''}>${roomType.description}</option>
              </c:forEach>
            </select>
          </div>
        </div>
      </div>
        
      <div class="modal-footer">
        <button type="submit" class="btn btn-success btn-shadow btn-shadow-success x-btn">确定</button>&nbsp;&nbsp;&nbsp;&nbsp;
        <button type="button" class="btn btn-default btn-shadow btn-shadow-default x-btn" data-dismiss="modal">取消</button>
      </div>
    </form>
  </div>
</div>
<script type="text/javascript">
  $(function() {
    $('select[name="siteId"]').select2({
        placeholder : '请选择门店',
        minimumResultsForSearch : -1,
        allowClear : true,
        width: '100%'
      });
  })
  
  $(function() {
    $('select[name="coachId"]').select2({
        placeholder : '请选择教练',
        minimumResultsForSearch : -1,
        allowClear : true,
        width: '100%'
      });
  })
  
  $(function() {
    $('select[name="hour"]').select2({
        placeholder : '请选择时间',
        minimumResultsForSearch : -1,
        allowClear : true,
        width: '100%'
      });
  })
  
  $(function() {
    $('select[name="occurHour"]').select2({
        placeholder : '请选择时间',
        minimumResultsForSearch : -1,
        allowClear : true,
        width: '100%'
      });
  })
  
  $(function() {
    $('select[name="roomType"]').select2({
        placeholder : '请选择区域类型',
        minimumResultsForSearch : -1,
        allowClear : true,
        width: '100%'
      });
  })
</script>